package medium;

/**
 * 274. H指数
 * 地址：https://leetcode.cn/problems/h-index/description/
 */
public class H指数_274 {
    public static void main(String[] args) {
        int[] citations = {3,0,6,1,5};
        System.out.println(hIndex(citations));
    }

    public static int hIndex(int[] citations) {
        int n = citations.length;
        int[] cnt = new int[n+1];
        for (int citation : citations) {
            cnt[Math.min(citation, n)]++;
        }

        int res = 0;
        for (int i = cnt.length-1; i >= 0; i--) {
            res += cnt[i];
            if (res >= i) {
                res = i;
                break;
            }
        }
        return res;
    }
}
